/////////////////////////////////////////////////////////////////////////////////////////////
//
//      COPYRIGHT 2010 MYLES HATHCOCK
//
//      This source code is provided for all, Open-Source, under this OpenBSD License.
//      It follows all terms and agreements listed there.
//
//      All structure code comments should be in doxygen format.
//
/////////////////////////////////////////////////////////////////////////////////////////////

#ifndef HE_TIMINGMANAGER_HPP_INCLUDED
#define HE_TIMINGMANAGER_HPP_INCLUDED

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>



/**
*   \brief  Class - cTimingManager
*
*   \par    This class manages execution rate of the Servo Hardware.
*
*/

class cTimingManager
{
    /// This class does not need to inherit from anything, nor will it have any children. Its standalone!

    //-----------------------------------------------//
    //------------------ PUBLIC ---------------------//
    //-----------------------------------------------//

    public:

        //  Construction
        cTimingManager();

        //  Destruction
        ~cTimingManager();

        //--------------- Public Methods ------------------//

        /// StartTimer - This stores the most recent system time accurate to microseconds
        void StartTimer();

        /// FinishRTI - This checks how much time is left before the main loop must continue, and waits that long.
        void FinishRTI();

        /// SetFrequency - This allows outside callers to set how many times per second the servos will attempt to update. UP TO 50hz (hardware limit)
        void SetFrequency( int Frequency );

        /// EnableDebugOutput - Turns on several print statements to assist in debugging
        void EnableDebugOutput() { mDebuggingOutput = true; }

    //----------------------------------------------//
    //------------------ PRIVATE -------------------//
    //----------------------------------------------//

    private:

        //  Any Needed private methods go here


        //  Private member vars (ALL member vars should be private)
        int mCurrentFrequency;

        double mSecPerRTI;
        double mStartingTime;
        double mFinishingTime;
        double mWaitingTime;

        bool mDebuggingOutput;

        //  Timekeepers
        struct timeval sStartingTime;
        struct timeval sFinishingTime;
        useconds_t mWait_USec;

};



#endif // HE_TIMINGMANAGER_HPP_INCLUDED











